package com.zhan.ielts.web.controller;

import java.util.HashMap;
import java.util.Map;

import com.zhan.frame.core.utils.EnvPropertiesUtil;
import com.zhan.ielts.utils.JsonUtils;
import com.zhan.ielts.utils.NetUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhan.frame.core.dao.BaseService;
import com.zhan.frame.core.web.controller.BaseControllerImpl;
import com.zhan.frame.core.web.domain.CustomResult;
import com.zhan.ielts.domain.AppCheck;
import com.zhan.ielts.domain.query.AppCheckQuery;
import com.zhan.ielts.service.AppCheckService;

@Controller
@RequestMapping("/app/check")
public class AppCheckController extends BaseControllerImpl<AppCheck, AppCheckQuery> {

	private Logger log = LoggerFactory.getLogger(AppCheckController.class);

	@Autowired
	private AppCheckService appCheckService;

	@Override
	protected BaseService<AppCheck> getBaseService() {
		return appCheckService;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ResponseBody
	@RequestMapping(value = "/fetch/{type}", method = RequestMethod.GET)
	public CustomResult fetchLatestOne(@PathVariable("type") String type) {
		log.info("获取最新版本开始");
		String url = EnvPropertiesUtil.getProperties("commonSystemUrl") + "/appRelease/fetch/" + type;
		log.info("fetchLatestOne url is {}", url);
		String result = NetUtils.doGet(url);
		CustomResult jsonResult = JsonUtils.fromJson(result, CustomResult.class);
		log.info("获取最新版本结束");
		return jsonResult;
	}

}
